﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DriveBeamEditor.Tools
{
    public static class Imaging
    {
        public static Color Blend(Color front, Color back, int alpha)
        {
            var frontColor = Color.FromArgb(255, front);
            var backColor = Color.FromArgb(255, back);

            var frontRed = frontColor.R;
            var frontGreen = frontColor.G;
            var frontBlue = frontColor.B;
            var backRed = backColor.R;
            var backGreen = backColor.G;
            var backBlue = backColor.B;

            var fRed = ((float)frontRed * alpha) / 255 + backRed * ((float)(255 - alpha) / 255);
            var newRed = (byte)fRed;
            var fGreen = ((float)frontGreen * alpha) / 255 + backGreen * ((float)(255 - alpha) / 255);
            var newGreen = (byte)fGreen;
            var fBlue = ((float)frontBlue * alpha) / 255 + backBlue * ((float)(255 - alpha) / 255);
            var newBlue = (byte)fBlue;

            return Color.FromArgb(255, newRed, newGreen, newBlue);
        }
    }
}
